#pragma once

#include"Mutex.hpp"
#include <pthread.h>

using namespace MutexModule;

namespace CondModule
{
    class Cond
    {
    public:
        Cond()
        {
            pthread_cond_init(&_cond, nullptr);
        }

        void Wait(Mutex & mutex)
        {
            int n = pthread_cond_wait(&_cond, mutex.Get());
        }

        void Signal() //  唤醒单个线程
        {
            int n = pthread_cond_signal(&_cond);
        }

        void Broadcast()// 唤醒所有线程
        {
            int n = pthread_cond_broadcast(&_cond);
        }

        ~Cond()
        {
            pthread_cond_destroy(&_cond);
        }
    private:
        pthread_cond_t _cond;
    };
}